package com.cqie.tes.controller.evalute;

import com.cqie.tes.comm.R;
import com.cqie.tes.config.MyUserDetile;
import com.cqie.tes.domain.qo.tes.evalute.EvaluteQo;
import com.cqie.tes.domain.vo.tes.evalute.AnswerPo;
import com.cqie.tes.service.evalute.EvaluteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/evalute")
public class EvaluteController {

    @Autowired
    EvaluteService evaluteService;

//    // TODO AnswerPo 偷懒记着改
//    @PostMapping("/itemAnswerList")
//    public R itemAnswerList(@RequestBody AnswerPo answerPo){
//        MyUserDetile principal = (MyUserDetile) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        Long id = principal.getSysUser().getId();
//        answerPo.setUserId(id);
//        return evaluteService.getItemAnswerList(answerPo);
//    }

    @PostMapping("/optionlist")
    public R optionList(){
        return evaluteService.optionList();
    }

    @PostMapping("submitanswer")
    public R submitAnswer(@RequestBody AnswerPo answerPo){
        MyUserDetile principal = (MyUserDetile) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long id = principal.getSysUser().getId();
        answerPo.setUserId(id);
        log.info("当前测试用户id : {}",answerPo.getUserId());
        log.info("答案 : {}",answerPo);
        return evaluteService.saveAnswer(answerPo);
    }

    // TODO ========bug 是因为没带上===========
    /**
     * clazzId
     * courseId
     * employeId
     * taskId
     * 缺一不可
     * */

    @PostMapping("/studentList")
    public R studentList(EvaluteQo qo){
        MyUserDetile principal = (MyUserDetile) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long id = principal.getSysUser().getId();
        qo.setId(id);
        log.info("当前测试用户id : {} 学生",qo.getId());
        return evaluteService.studentList(qo);
    }

    @PostMapping("/zipinList")
    public R zipinList(EvaluteQo qo) {
        MyUserDetile principal = (MyUserDetile) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long id = principal.getSysUser().getId();
        qo.setId(id);
        log.info("当前测试用户id : {}", qo.getId());
        return evaluteService.zipinList(qo);
    }


    @PostMapping("/hupinList")
    public R hupinList(EvaluteQo qo) {
        MyUserDetile principal = (MyUserDetile) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long id = principal.getSysUser().getId();
        qo.setId(id);
        log.info("当前测试用户id : {}", qo.getId());
        return evaluteService.hupinList(qo);
    }

    @PostMapping("/jiaoyanshiList")
    public R jiaoyanshiList(EvaluteQo qo) {
        MyUserDetile principal = (MyUserDetile) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long id = principal.getSysUser().getId();
        qo.setId(id);
        log.info("当前测试用户id : {}", qo.getId());
        return evaluteService.jiaoyanshiList(qo);
    }


    @PostMapping("/xibuList")
    public R xibuList(EvaluteQo qo) {
        MyUserDetile principal = (MyUserDetile) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long id = principal.getSysUser().getId();
        qo.setId(id);
        log.info("当前测试用户id : {}", qo.getId());
        return evaluteService.xibuList(qo);
    }


    /**
     * 查询试题列表
     * */
    @PostMapping("/studentgetItemListe")
    public R studentgetItemListe(AnswerPo answerPo){
        MyUserDetile principal = (MyUserDetile) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long id = principal.getSysUser().getId();
        answerPo.setUserId(id);
        return evaluteService.studentgetItemListe(answerPo);
    }

    @PostMapping("/zipingetItemListe")
    public R zipingetItemListe(AnswerPo answerPo){
        MyUserDetile principal = (MyUserDetile) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long id = principal.getSysUser().getId();
        answerPo.setUserId(id);
        return evaluteService.zipingetItemListe(answerPo);
    }

    @PostMapping("/hupingetItemListe")
    public R hupingetItemListe(AnswerPo answerPo){
        MyUserDetile principal = (MyUserDetile) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long id = principal.getSysUser().getId();
        answerPo.setUserId(id);
        return evaluteService.hupingetItemListe(answerPo);
    }

    @PostMapping("/jiaoyanshigetItemListe")
    public R jiaoyanshigetItemListe(AnswerPo answerPo){
        MyUserDetile principal = (MyUserDetile) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long id = principal.getSysUser().getId();
        answerPo.setUserId(id);
        return evaluteService.jiaoyanshigetItemListe(answerPo);
    }

    @PostMapping("/xibugetItemListe")
    public R xibugetItemListe(AnswerPo answerPo){
        MyUserDetile principal = (MyUserDetile) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long id = principal.getSysUser().getId();
        answerPo.setUserId(id);
        return evaluteService.xibugetItemListe(answerPo);
    }



}
